package com.LeetCode.String;

import org.junit.Test;

/**
 * 字符串相加
 */
public class AddString {
    public String addStrings(String num1, String num2) {
        StringBuilder strb = new StringBuilder();
        int carry = 0, i = num1.length() - 1, j = num2.length() - 1;
        while(i >= 0 || j >= 0 || carry != 0){
            if(i >= 0) carry += num1.charAt(i--) - '0';
            if(j >= 0) carry += num2.charAt(j--) - '0';
            strb.append(carry % 10);
            carry /= 10;
        }
        return strb.reverse().toString();

    }

    @Test
    public void test(){
        String a = "123";
        String b = "456";
        System.out.println(addStrings(a,b));
    }
}
